package main;

import java.io.IOException;

import javax.microedition.media.MediaException;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class MainMidlet extends MIDlet {
	// PlayingCanvas playingCanvas;
	MenuCanvas menuCanvas;
	PauseCanvas pauseCanvas;
	SellectGameCanvas sellectGameCanvas;

	public void startApp() {
		show(new SoundOnCanvas(this));

	}

	public void starGame(boolean soundOn) {
		try {
			Res.init();
			Res.soundOn = soundOn;
		} catch (IOException e) {
			e.printStackTrace();
		} catch (MediaException e) {
			e.printStackTrace();
		}
		PlayingCanvas.init(this);
		menuCanvas = new MenuCanvas(this);
		pauseCanvas = new PauseCanvas(this);
		sellectGameCanvas = new SellectGameCanvas(this);

		showMenuCanvas();
	}

	public void pauseApp() {
		System.out.println("pause");
		if (PlayingCanvas.getInstance() != null
				&& PlayingCanvas.getInstance().isPlaying()) {
			PlayingCanvas.getInstance().stop();
			showPauseCanvas();
		}
	}

	public void destroyApp(boolean unconditional) {
	}

	public void show(Displayable d) {
		Display.getDisplay(this).setCurrent(d);
	}

	public void showPlayingCanvas() {
		PlayingCanvas.getInstance().start();
		show(PlayingCanvas.getInstance());
	}

	public void showPauseCanvas() {
		show(pauseCanvas);
	}

	public void showAboutCanvas() {
		show(new AboutCanvas(this));
	}

	public void showHelpCanvas() {
		show(new HelpCanvas(this));
	}

	public void showOptionCanvas() {
		show(new OptionCanvas(this));
	}

	public void showSellectGameCanvas() {
		sellectGameCanvas.update();
		show(sellectGameCanvas);
		//show(menuCanvas);
	}

	public void showMenuCanvas() {
		show(menuCanvas);
	}

	public void showGameOverCanvas(boolean win) {
		show(new GameOverCanvas(this, win));
	}
}
